package org.example.lease.config;

import org.example.lease.custom.converters.StringToItemTypeConverters;
import org.example.lease.custom.converters.StringToReleaseStatusConverters;
import org.example.lease.custom.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import jakarta.annotation.Resource;

/**
 * @author 宋孟林
 * @description 将自定义的stringToTypeItem注册到mvc配置中
 * @date: 2025/5/15 19:20
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private StringToItemTypeConverters stringToItemTypeConverters;
    @Resource
    private StringToReleaseStatusConverters stringToReleaseStatusConverters;
    @Resource
    private AuthenticationInterceptor authenticationInterceptor;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(this.stringToItemTypeConverters);
        registry.addConverter(this.stringToReleaseStatusConverters);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor).addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/login/**");
    }
}
